#ifndef BLACKJACKGAME_H
#define BLACKJACKGAME_H

#include <QHBoxLayout>

#include <QFrame>

#include <QLabel>
#include <QPushButton>
#include <QSpinBox>

#include <QFont>

#include <QPalette>

#include "games/basegame.h"

// BlackJackGame: provide a blackjack game
class BlackJackGame : public BaseGame
{
    Q_OBJECT
public:
    // Constructor
    explicit BlackJackGame(QWidget *parent = 0, int difflvl = 1);

    // Members
    bool isSolved() { if( one_played ) return true; return false; }
    QString hint() { return "May the force be with you."; }

    // New game is prepared (for Again!)
    void restart();

    // Points and winning actions
    QList<int> getValues(const QStringList &cards);
    bool checkOverflow(const QList<int>& list);
    bool checkBlackjack(const QStringList &list);

    // Players actions
    QString drawCard();

    void dealerDrawCard();
    void playerDrawCard();

    void startupTurns();
    void dealerTurns();
    void endTurns();

    // UI update
    void updatePoints();

public slots:
    // Slots for buttons
    void onInsuranceButtonClicked();
    void onDoubleButtonClicked();
    void onSplitButtonClicked();
    void onStayButtonClicked();
    void onHitButtonClicked();
    void onNewButtonClicked();

private:
    // Cards and points label
    QLabel * dealer_cards_label;
    QLabel * dealer_points_label;
    QLabel * player_cards_label;
    QLabel * player_points_label;

    QFrame * hline;

    QHBoxLayout * hor_lay;

    QPushButton * insurance_button;
    QPushButton * double_button;
    QPushButton * split_button;
    QPushButton * stay_button;
    QPushButton * hit_button;
    QPushButton * new_button;

    QSpinBox * bet_spinbox;

    // Flag for 1 turn played
    bool one_played;

    // Counters for points and bet
    int points;
    int bet;

    // Deck variables
    int cards_left;
    QStringList deck;

    // Players cards and points and blackjack flag
    QStringList dealer_cards;
    QStringList player_cards;

    QList<int> dealer_points;
    QList<int> player_points;

    bool dealer_blackjack;
    bool player_blackjack;
};

#endif // BLACKJACKGAME_H
